from pydantic import BaseModel
from typing import Optional, List
import uuid

class LabelIn(BaseModel):
    project_id: Optional[uuid.UUID] = None
    parent_id: Optional[uuid.UUID] = None
    name: str
    color: Optional[str] = None
    description: Optional[str] = None
    sort: int = 0

class LabelOut(LabelIn):
    id: uuid.UUID

class TextDocIn(BaseModel):
    project_id: Optional[uuid.UUID] = None
    title: Optional[str] = None
    content: str
    encoding: Optional[str] = None

class TextDocOut(TextDocIn):
    id: uuid.UUID

class AnnotationIn(BaseModel):
    doc_id: uuid.UUID
    label_id: uuid.UUID
    start_offset: int
    end_offset: int
    text: str

class AnnotationOut(AnnotationIn):
    id: uuid.UUID

class ApiResponse(BaseModel):
    code: int = 0
    message: str = "ok"
    data: Optional[dict | list] = None

class LabelTreeNode(BaseModel):
    id: uuid.UUID
    name: str
    color: Optional[str] = None
    description: Optional[str] = None
    sort: int = 0
    children: List["LabelTreeNode"] = []

LabelTreeNode.model_rebuild()
